package com.leigang.java.code.design.mode.observer;

import com.leigang.java.code.design.mode.observer.display.DyDisplay;
import com.leigang.java.code.design.mode.observer.display.WechatDisplay;
import com.leigang.java.code.design.mode.observer.display.ZfbDisplay;

public class ObserverPatternDemo {
    public static void main(String[] args) {
        WeatherStation weatherStation = new WeatherStation();
        WechatDisplay wechatDisplay = new WechatDisplay("微信");
        ZfbDisplay zfbDisplay = new ZfbDisplay("支付宝");
        DyDisplay dyDisplay = new DyDisplay("抖音");

        weatherStation.registerObserver(wechatDisplay);
        weatherStation.registerObserver(zfbDisplay);
        weatherStation.registerObserver(dyDisplay);
        // 更新天气
        weatherStation.setWeather("晴天");
        System.out.println("======================");
        // 移除一个观察者
        weatherStation.removeObserver(dyDisplay);
        // 再次更新天气
        weatherStation.setWeather("雨天");
    }
}
